home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’96
/
Menu Thief
/
main.cp
next >
Wrap
Text File
|
1996-06-21
|
2KB
|
110 lines
// main.cp
// by David Kamholz
#include <Retrace.h>
inline void SetMBarHeight(void);
void RestoreGrayRgn(void);
pascal void myVBL(register VBLTaskPtr vblTaskPtr:__a0);
/*
short v1:0x828;
short h1:0x82A;
short v2:0x82C;
short h2:0x82E;
*/
short v3:0x830; // mouse y coordinate
//short h3:0x832; // mouse x coordinate
const kMenuBarHeight = 20;
const kMenuDistance = 5;
RgnHandle theMenus[kMenuBarHeight+1];
RgnHandle theGrays[kMenuBarHeight];
void main(void)
{
InitGraf(&qd.thePort);
InitWindows();
InitCursor();
InitDialogs(nil);
InitMenus();
TEInit();
Handle theMenu = GetNewMBar(128);
SetMenuBar(theMenu);
DrawMenuBar();
FlushEvents(everyEvent, -1L);
RgnHandle grayRgn = LMGetGrayRgn();
short i;
for (i = kMenuBarHeight; i >= 0; i--) {
theMenus[i] = NewRgn();
CopyRgn(grayRgn, theMenus[i]);
if (i == kMenuBarHeight) continue;
theGrays[i] = NewRgn();
Rect mBarRect;
SetRect(&mBarRect,
qd.screenBits.bounds.left,
qd.screenBits.bounds.top + i,
qd.screenBits.bounds.right,
qd.screenBits.bounds.top + kMenuBarHeight); // what was the menu bar but now is not
RectRgn(theGrays[i], &mBarRect);
UnionRgn(theMenus[i], theGrays[i], theMenus[i]);
}
VBLTask theVBL;
theVBL.qType = 1;
theVBL.vblAddr = NewVBLProc(myVBL);
theVBL.vblCount = 1; // how often it's called
theVBL.vblPhase = 0;
OSErr err;
err = VInstall((QElemPtr)&theVBL);
while (!Button()) ;
err = VRemove((QElemPtr)&theVBL);
LMSetMBarHeight(kMenuBarHeight);
CopyRgn(theMenus[kMenuBarHeight], grayRgn);
LMSetGrayRgn(grayRgn);
DrawMenuBar();
for (i = 0; i < kMenuBarHeight; i++) {
DisposeRgn(theMenus[i]);
DisposeRgn(theGrays[i]);
}
DisposeRgn(theMenus[kMenuBarHeight]);
}
pascal void myVBL(register VBLTaskPtr vblTaskPtr:__a0) {
if (v3 < kMenuBarHeight+kMenuDistance-1) {
short which;
if (v3 < kMenuDistance) which = 0;
else which = v3 - kMenuDistance + 1;
LMSetMBarHeight(which);
LMSetGrayRgn(theMenus[which]);
DrawMenuBar();
PaintOne(nil, theGrays[which]);
}
else {
if (LMGetMBarHeight() != kMenuBarHeight) {
LMSetMBarHeight(kMenuBarHeight);
LMSetGrayRgn(theMenus[kMenuBarHeight]);
DrawMenuBar();
}
}
vblTaskPtr->vblCount = 1; // reset it so it will be called again
}